import { getDateVersion, printJSON} from '../src/utils'
import {expect} from 'chai'
import * as step from '@flow-step/step-toolkit'
import * as sinon from 'sinon';
import moment from 'moment'


describe('getDateVersion', () => {
    it('should return the current date and time in YYYYMMDDHHmmss format', () => {
        const mockDate = new Date('2024-10-11T10:34:56Z');
        const clock = sinon.useFakeTimers(mockDate);

        const result = getDateVersion();

        const expectedDate = moment(mockDate).format('YYYYMMDDHHmmss');
        expect(result).to.equal(expectedDate);

        clock.restore();
    });
});



describe('printJSON', () => {
    let stepInfoStub: sinon.SinonStub;

    beforeEach(() => {
        stepInfoStub = sinon.stub(step, 'info')
    });

    afterEach(() => {
        stepInfoStub.restore();
    });

    it('should correctly print a JSON object', () => {
        const testData = {
            key1: 'value1',
            key2: 'value2'
        };

        printJSON(testData);

        expect(stepInfoStub.calledWith('{')).to.be.true;
        expect(stepInfoStub.calledWith('    "key1": "value1",')).to.be.true;
        expect(stepInfoStub.calledWith('    "key2": "value2",')).to.be.true;
        expect(stepInfoStub.calledWith('}')).to.be.true;
    });

    it('should handle empty objects', () => {
        const testData = {};

        printJSON(testData);

        expect(stepInfoStub.calledWith('{')).to.be.true;
        expect(stepInfoStub.calledWith('}')).to.be.true;
    });
});
